/*
 *  Copyright 2010 Massimiliano Mazzarolo
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *     http://www.apache.org/licenses/LICENSE-2.0
 *        
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 */
package grails.coherence;

import com.tangosol.util.filter.AllFilter;
import com.tangosol.util.filter.AlwaysFilter;
import com.tangosol.util.filter.AnyFilter;

import grails.coherence.exceptions.MalformedFilterException;
import grails.test.GrailsUnitTestCase;
import groovy.mock.interceptor.MockFor;

import static grails.coherence.MultiFilterContainer.*

class MultiContainerFilterTests extends GrailsUnitTestCase {
	
	void test_AND_type_shouldReturn_AllFilter() {		
		assert create(AND).process() instanceof AllFilter		
	}
	
	void test_OR_type_shouldReturn_AnyFilter() {		
		assert create(OR).process() instanceof AnyFilter		
	}
	
	void test_SINGLE_type_shouldReturnFirstFilterOfTheStack() {		
		def underTest = create(SINGLE)
		def filter = new AlwaysFilter()
		underTest << filter
		assertSame(filter, underTest.process())
	}
		
	void testExceptionWhenMultipleFiltersInSingleContainer() {		
		def underTest = create(SINGLE)
		def filter = new AlwaysFilter()
		def anotherFilter = new AlwaysFilter()
		underTest << filter << anotherFilter
		try {
			underTest.process()
			fail()
		} catch (MalformedFilterException e) {
			
		}
	}
		
	private MultiFilterContainer create(type) {
		new MultiFilterContainer(type:type)
	}
}
